package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;

import com.jwdf.uda.databinding.ItemGuideTextTitleTabBinding;
import com.jwdf.uda.event.GuideDetailEvent;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.EventBusUtil;

/**
 * 类说明：
 */
public class GuideTitleTabViewHolder extends AbsViewHolder<GuideDetailItem>{
    private ItemGuideTextTitleTabBinding mBinding;
    public GuideTitleTabViewHolder(View convertView) {
        super(convertView);
        mBinding = DataBindingUtil.bind(convertView);
    }

    @Override
    protected void onBindView(final GuideDetailItem item) {
        mBinding.tvTabComment.setText(String.valueOf(item.commentCount));
        mBinding.tvTabPraise.setText(String.valueOf(item.likeCount));

        if(item.currentTab == GuideDetailItem.GuideTab.LIKE){
            showTabPraise();
        }else{
            showTabComment();
        }

        mBinding.flTabComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.currentTab = GuideDetailItem.GuideTab.COMMENT;
                GuideDetailEvent event=new GuideDetailEvent(GuideDetailEvent.EVENT_TAB_COMMENT);
                event.count=item.commentCount;
                EventBusUtil.post(event);
            }
        });
        mBinding.flTabPraise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.currentTab = GuideDetailItem.GuideTab.LIKE;
                GuideDetailEvent event= new GuideDetailEvent(GuideDetailEvent.EVENT_TAB_LIKE);
                event.count=item.likeCount;
                EventBusUtil.post(event);
            }
        });
    }

    private void showTabComment() {
        mBinding.tvTabComment.setSelected(true);
        mBinding.tvGuideTitleComment.setSelected(true);
        mBinding.tvGuideTitleLike.setSelected(false);
        mBinding.tvTabPraise.setSelected(false);
        mBinding.vLineComment.setVisibility(View.VISIBLE);
        mBinding.vLinePraise.setVisibility(View.GONE);
    }

    private void showTabPraise() {
        mBinding.tvTabComment.setSelected(false);
        mBinding.tvGuideTitleLike.setSelected(true);
        mBinding.tvGuideTitleComment.setSelected(false);
        mBinding.tvTabPraise.setSelected(true);
        mBinding.vLineComment.setVisibility(View.GONE);
        mBinding.vLinePraise.setVisibility(View.VISIBLE);
    }
}
